using Microsoft.SqlServer.Management.SqlManagerUI.Scripting;
using Microsoft.SqlServer.Management.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Microsoft.SqlServer.Management.SqlManagerUI
{
	[ComVisible(false)]
	public class OutputOptionsWizardPage : WizardPage
	{
		private RadioButton idRadioScriptToFile;

		private Separator idSepScriptMode;

		private RadioButton idRadioScriptToClipboard;

		private RadioButton idRadioEditor;

		private Panel panel2;

		private Panel panel1;

		private RadioButton idSaveAsANSI;

		private RadioButton idSaveAsUnicode;

		private Label idLabelSaveAs;

		private Label idLabelFileName;

		private Button idBrowse;

		private TextBox idFileName;

		private GenScriptWizForm parent;

		private Panel panel3;

		private RadioButton idFilePerObject;

		private RadioButton idSingleFile;

		private Label fileGenerateLabel;

		private CheckBox chbOverwriteFile;

		private RadioButton rdbMultipleFile;

		private Panel pnlMultipleFiles;

		private Label lblDirectoryName;

		private Button btnBrowseDirectories;

		private TextBox txtDirectoryName;

		private RadioButton rdbPublish;

		private Panel pnlPublish;

		private ComboBox cmdTargetDatabases;

		private ComboBox cmdProviders;

		private Label lblTargetDatabase;

		private Label lblProvider;

		private Button btnProviders;

		private GenWizGeneralData fileOption;

		private Label lblPublishWarning;

		private ProviderCollection _providers;

		public OutputOptionsWizardPage(WizardForm wizard) : base(wizard)
		{
			this.InitializeComponent();
			this.LoadStrings();
			this.parent = (GenScriptWizForm)wizard;
			base.PageID = 21;
			this.fileOption = (GenWizGeneralData)base.WizardInputs.FindItem(0);
			this.SubTitle = GenScriptWizSR.FileOptionSubtitle;
			this.Title = GenScriptWizSR.FileOptionTitle;
			base.HelpTopicKeyword = "sql9.swb.generatescriptswizard.scriptfileoption.f1";
			this.idBrowse.Click += new EventHandler(this.idBrowse_Click);
			this.fileOption.SaveFileType = GenWizGeneralData.ScriptFileType.UNICODE;
			this.idRadioScriptToFile.Checked = true;
			base.FinishEnabled = true;
		}

		private void idBrowse_Click(object sender, EventArgs e)
		{
			if (this.idSingleFile.Checked)
			{
				using (SaveFileDialog saveFileDialog = new SaveFileDialog())
				{
					saveFileDialog.Filter = GenScriptWizSR.ScriptFileFilter;
					saveFileDialog.InitialDirectory = Path.GetDirectoryName(this.fileOption.SaveFileName);
					saveFileDialog.Title = GenScriptWizSR.ScriptFileLocation;
					saveFileDialog.OverwritePrompt = false;
					DialogResult dialogResult = saveFileDialog.ShowDialog();
					if (DialogResult.OK == dialogResult && saveFileDialog.FileName.Length != 0)
					{
						this.fileOption.SaveFileName = saveFileDialog.FileName;
						this.idFileName.Text = this.fileOption.SaveFileName;
					}
					return;
				}
			}
			using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
			{
				folderBrowserDialog.Description = GenScriptWizSR.ScriptFileLocation;
				folderBrowserDialog.SelectedPath = Path.GetDirectoryName(this.fileOption.SaveFileName);
				DialogResult dialogResult2 = folderBrowserDialog.ShowDialog();
				if (DialogResult.OK == dialogResult2)
				{
					this.fileOption.SaveFileName = folderBrowserDialog.SelectedPath;
					this.idFileName.Text = this.fileOption.SaveFileName;
				}
			}
		}

		protected override void OnEnterPage(EventArgs e)
		{
			this.Wizard.BackEnabled = true;
			this.Wizard.NextEnabled = true;
			bool flag = base.WizardInputs.FindBool(3);
			if (flag)
			{
				base.FinishEnabled = true;
			}
			else
			{
				base.FinishEnabled = false;
			}
			this.idFileName.Text = this.fileOption.SaveFileName;
			if (this.rdbPublish.Checked && (this.cmdProviders.SelectedItem == null || this.cmdTargetDatabases.SelectedItem == null))
			{
				this.parent.NextButton.Enabled = false;
				this.parent.FinishButton.Enabled = false;
			}
			this.chbOverwriteFile.Checked = this.fileOption.OverwriteExistingFile;
		}

		protected override void OnInitializePage(EventArgs e)
		{
			this.idRadioScriptToFile.Checked = true;
			this.rdbPublish.Checked = false;
			this.rdbMultipleFile.Checked = false;
		}

		protected override void OnLeavePage(LeavePageEventArgs e)
		{
			this.fileOption.FileInfoValidated = false;
			this.fileOption.OverwriteExistingFile = this.chbOverwriteFile.Checked;
			if ((e.Button == WizardButton.Next || e.Button == WizardButton.Finish) && !this.parent.ValidateFileInfo())
			{
				e.Cancel = true;
			}
			GenWizOptionsBase genWizOptionsBase = (GenWizOptionsBase)base.WizardInputs.FindItem(1);
			if (this.fileOption.SaveScriptDestination == GenWizGeneralData.ScriptDestination.ToProvider)
			{
				ProviderEntity provider = this.fileOption.Provider;
				int sqlServerVersion = this.fileOption.SqlServerVersion;
				string arg_88_0 = string.Empty;
				if ((e.Button == WizardButton.Next || e.Button == WizardButton.Finish) && provider != null)
				{
					DatabaseEntity database = this.fileOption.Database;
					if ((string.IsNullOrEmpty(provider.UserName) || string.IsNullOrEmpty(provider.Password) || string.IsNullOrEmpty(database.UserName) || string.IsNullOrEmpty(database.Password)) && new RemoteCreditDialog
					{
						Provider = provider,
						Database = database
					}.ShowDialog(this) == DialogResult.Cancel)
					{
						e.Cancel = true;
						return;
					}
					try
					{
						WebServicePublishOptions webServicePublishOptions = new WebServicePublishOptions(new Uri(provider.WebServiceAddress), provider.UserName, provider.Password, database.ServerName, database.DatabaseName, database.UserName, database.Password);
						if (webServicePublishOptions.HasDatabaseServerVersion)
						{
							if (webServicePublishOptions.DatabaseServerVersionMajor == 8)
							{
								genWizOptionsBase.ScriptCompatibilityOption = GenWizOptionsBase.ScriptCompatabilityOptions.Script80Compat;
							}
							else if (webServicePublishOptions.DatabaseServerVersionMajor == 9)
							{
								genWizOptionsBase.ScriptCompatibilityOption = GenWizOptionsBase.ScriptCompatabilityOptions.Script90Compat;
							}
							else if (webServicePublishOptions.DatabaseServerVersionMajor == 10)
							{
								genWizOptionsBase.ScriptCompatibilityOption = GenWizOptionsBase.ScriptCompatabilityOptions.Script100Compat;
							}
						}
					}
					catch (Exception ex)
					{
						e.Cancel = true;
						GenScriptWizForm.ShowErrorMessageForProvider(this.parent.MessageProvider, provider, ex, this);
						if (ex is WebException && ((WebException)ex).Response is HttpWebResponse)
						{
							HttpWebResponse httpWebResponse = ((WebException)ex).Response as HttpWebResponse;
							if (httpWebResponse.StatusCode == HttpStatusCode.Unauthorized)
							{
								provider.UserName = string.Empty;
								provider.Password = string.Empty;
								database.UserName = string.Empty;
								database.Password = string.Empty;
							}
						}
					}
				}
				base.WizardInputs.AddEditItem(1, new GenWizPublishOptions(sqlServerVersion, genWizOptionsBase));
				return;
			}
			base.WizardInputs.AddEditItem(1, new GenWizTransferOptions(this.fileOption.SqlServerVersion, genWizOptionsBase));
		}

		private void OnFilePathChanged(object sender, EventArgs e)
		{
			this.fileOption.SaveFileName = this.idFileName.Text;
		}

		private void LoadStrings()
		{
			this.idRadioEditor.Text = GenScriptWizSR.FileOptionRadioEditorText;
			this.fileGenerateLabel.Text = GenScriptWizSR.FilesToGenerate;
			this.fileGenerateLabel.AccessibleName = GenScriptWizSR.MSAAFilesToGenerate;
			this.idSingleFile.Text = GenScriptWizSR.SingleFile;
			this.idSingleFile.AccessibleName = GenScriptWizSR.MSAASingleFile;
			this.idFilePerObject.Text = GenScriptWizSR.FilePerObject;
			this.idFilePerObject.AccessibleName = GenScriptWizSR.MSAAFilePerObject;
			this.idSepScriptMode.Text = GenScriptWizSR.FileOptionScriptMode;
			this.idRadioScriptToFile.Text = GenScriptWizSR.FileOptionRadioFileText;
			this.idRadioScriptToFile.AccessibleName = GenScriptWizSR.MSAAFileOptionRadioFileText;
			this.idSepScriptMode.Text = GenScriptWizSR.FileOptionOptionsText;
			this.idRadioScriptToClipboard.Text = GenScriptWizSR.FileOptionScriptToClipboard;
			this.idRadioScriptToClipboard.AccessibleName = GenScriptWizSR.MSAAFileOptionScriptToClipboard;
			this.idLabelFileName.Text = GenScriptWizSR.FileOptionsFileName;
			this.idLabelSaveAs.Text = GenScriptWizSR.FileOptionsSaveAs;
			this.idSaveAsANSI.Text = GenScriptWizSR.FileOptionSaveAsANSI;
			this.idSaveAsANSI.AccessibleName = GenScriptWizSR.MSAAFileOptionSaveAsANSI;
			this.idSaveAsUnicode.Text = GenScriptWizSR.FileOptionSaveAsUNICODE;
			this.idSaveAsUnicode.AccessibleName = GenScriptWizSR.MSAAFileOptionSaveAsUNICODE;
			this.idBrowse.Text = GenScriptWizSR.BrowseText;
			this.idBrowse.AccessibleName = GenScriptWizSR.MSAABrowseText;
			this.idFileName.AccessibleName = GenScriptWizSR.MSAAFileOptionsEditControl;
			this.chbOverwriteFile.Text = GenScriptWizSR.OverwriteExistingFile;
			this.rdbMultipleFile.Text = GenScriptWizSR.SelectMultipleFiles;
			this.rdbPublish.Text = GenScriptWizSR.SelectProvider;
			this.lblDirectoryName.Text = GenScriptWizSR.DirectoryName;
			this.btnBrowseDirectories.Text = GenScriptWizSR.BrowseText;
			this.lblProvider.Text = GenScriptWizSR.Provider;
			this.lblTargetDatabase.Text = GenScriptWizSR.TargetDatabase;
			this.btnProviders.Text = GenScriptWizSR.MoreText;
			this.lblPublishWarning.Text = GenScriptWizSR.PublishingWarning;
		}

		private void InitializeComponent()
		{
			this.idRadioScriptToFile = new RadioButton();
			this.idSepScriptMode = new Separator();
			this.idRadioScriptToClipboard = new RadioButton();
			this.idRadioEditor = new RadioButton();
			this.panel2 = new Panel();
			this.chbOverwriteFile = new CheckBox();
			this.idLabelFileName = new Label();
			this.idBrowse = new Button();
			this.idFileName = new TextBox();
			this.panel3 = new Panel();
			this.idFilePerObject = new RadioButton();
			this.idSingleFile = new RadioButton();
			this.fileGenerateLabel = new Label();
			this.panel1 = new Panel();
			this.idSaveAsANSI = new RadioButton();
			this.idSaveAsUnicode = new RadioButton();
			this.idLabelSaveAs = new Label();
			this.rdbMultipleFile = new RadioButton();
			this.pnlMultipleFiles = new Panel();
			this.lblDirectoryName = new Label();
			this.btnBrowseDirectories = new Button();
			this.txtDirectoryName = new TextBox();
			this.rdbPublish = new RadioButton();
			this.pnlPublish = new Panel();
			this.lblPublishWarning = new Label();
			this.cmdTargetDatabases = new ComboBox();
			this.cmdProviders = new ComboBox();
			this.lblTargetDatabase = new Label();
			this.lblProvider = new Label();
			this.btnProviders = new Button();
			this.panel2.SuspendLayout();
			this.pnlMultipleFiles.SuspendLayout();
			this.pnlPublish.SuspendLayout();
			base.SuspendLayout();
			this.idRadioScriptToFile.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idRadioScriptToFile.Checked = true;
			this.idRadioScriptToFile.Location = new Point(16, 31);
			this.idRadioScriptToFile.Name = "idRadioScriptToFile";
			this.idRadioScriptToFile.Size = new Size(374, 17);
			this.idRadioScriptToFile.TabIndex = 0;
			this.idRadioScriptToFile.TabStop = true;
			this.idRadioScriptToFile.Text = GenScriptWizSR.FileOptionRadioFileText;
			this.idRadioScriptToFile.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.idSepScriptMode.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idSepScriptMode.Location = new Point(3, 12);
			this.idSepScriptMode.Name = "idSepScriptMode";
			this.idSepScriptMode.Size = new Size(448, 16);
			this.idSepScriptMode.TabIndex = 0;
			this.idSepScriptMode.Text = GenScriptWizSR.FileOptionScriptMode;
			this.idRadioScriptToClipboard.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idRadioScriptToClipboard.Location = new Point(36, 165);
			this.idRadioScriptToClipboard.Name = "idRadioScriptToClipboard";
			this.idRadioScriptToClipboard.Size = new Size(365, 17);
			this.idRadioScriptToClipboard.TabIndex = 3;
			this.idRadioScriptToClipboard.Text = GenScriptWizSR.FileOptionScriptToClipboard;
			this.idRadioScriptToClipboard.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.idRadioEditor.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idRadioEditor.Location = new Point(36, 186);
			this.idRadioEditor.Name = "idRadioEditor";
			this.idRadioEditor.Size = new Size(365, 17);
			this.idRadioEditor.TabIndex = 4;
			this.idRadioEditor.Text = GenScriptWizSR.FileOptionScriptToClipboard;
			this.idRadioEditor.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.panel2.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.panel2.Controls.Add(this.chbOverwriteFile);
			this.panel2.Controls.Add(this.idLabelFileName);
			this.panel2.Controls.Add(this.idBrowse);
			this.panel2.Controls.Add(this.idFileName);
			this.panel2.Location = new Point(25, 59);
			this.panel2.Name = "panel2";
			this.panel2.Size = new Size(426, 67);
			this.panel2.TabIndex = 1;
			this.chbOverwriteFile.AutoSize = true;
			this.chbOverwriteFile.Location = new Point(3, 30);
			this.chbOverwriteFile.Name = "chbOverwriteFile";
			this.chbOverwriteFile.Size = new Size(125, 17);
			this.chbOverwriteFile.TabIndex = 4;
			this.chbOverwriteFile.Text = GenScriptWizSR.OverwriteExistingFile;
			this.chbOverwriteFile.UseVisualStyleBackColor = true;
			this.idLabelFileName.Location = new Point(2, 7);
			this.idLabelFileName.Name = "idLabelFileName";
			this.idLabelFileName.Size = new Size(101, 13);
			this.idLabelFileName.TabIndex = 0;
			this.idLabelFileName.Text = GenScriptWizSR.SingleFile;
			this.idBrowse.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.idBrowse.Location = new Point(332, 30);
			this.idBrowse.Name = "idBrowse";
			this.idBrowse.Size = new Size(94, 23);
			this.idBrowse.TabIndex = 3;
			this.idBrowse.Text = GenScriptWizSR.BrowseText;
			this.idFileName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idFileName.Location = new Point(131, 4);
			this.idFileName.Name = "idFileName";
			this.idFileName.Size = new Size(295, 20);
			this.idFileName.TabIndex = 2;
			this.idFileName.TextChanged += new EventHandler(this.OnFilePathChanged);
			this.panel3.Location = new Point(132, 28);
			this.panel3.Name = "panel3";
			this.panel3.Size = new Size(274, 39);
			this.panel3.TabIndex = 4;
			this.idFilePerObject.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idFilePerObject.Location = new Point(0, 21);
			this.idFilePerObject.Name = "idFilePerObject";
			this.idFilePerObject.Size = new Size(210, 17);
			this.idFilePerObject.TabIndex = 1;
			this.idFilePerObject.Text = GenScriptWizSR.FilePerObject;
			this.idFilePerObject.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.idSingleFile.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idSingleFile.Checked = true;
			this.idSingleFile.Location = new Point(0, 0);
			this.idSingleFile.Name = "idSingleFile";
			this.idSingleFile.Size = new Size(210, 17);
			this.idSingleFile.TabIndex = 0;
			this.idSingleFile.TabStop = true;
			this.idSingleFile.Text = GenScriptWizSR.SingleFile;
			this.idSingleFile.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.fileGenerateLabel.Location = new Point(0, 29);
			this.fileGenerateLabel.Name = "fileGenerateLabel";
			this.fileGenerateLabel.Size = new Size(123, 38);
			this.fileGenerateLabel.TabIndex = 3;
			this.fileGenerateLabel.Text = GenScriptWizSR.FilesToGenerate;
			this.panel1.Location = new Point(132, 73);
			this.panel1.Name = "panel1";
			this.panel1.Size = new Size(274, 39);
			this.panel1.TabIndex = 6;
			this.idSaveAsANSI.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idSaveAsANSI.Location = new Point(0, 21);
			this.idSaveAsANSI.Name = "idSaveAsANSI";
			this.idSaveAsANSI.Size = new Size(210, 17);
			this.idSaveAsANSI.TabIndex = 1;
			this.idSaveAsANSI.Text = GenScriptWizSR.FileOptionSaveAsANSI;
			this.idSaveAsANSI.CheckedChanged += new EventHandler(this.SaveFileType_CheckedChanged);
			this.idSaveAsUnicode.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idSaveAsUnicode.Checked = true;
			this.idSaveAsUnicode.Location = new Point(0, 0);
			this.idSaveAsUnicode.Name = "idSaveAsUnicode";
			this.idSaveAsUnicode.Size = new Size(210, 17);
			this.idSaveAsUnicode.TabIndex = 0;
			this.idSaveAsUnicode.TabStop = true;
			this.idSaveAsUnicode.Text = GenScriptWizSR.FileOptionSaveAsUNICODE;
			this.idSaveAsUnicode.CheckedChanged += new EventHandler(this.SaveFileType_CheckedChanged);
			this.idLabelSaveAs.Location = new Point(0, 73);
			this.idLabelSaveAs.Name = "idLabelSaveAs";
			this.idLabelSaveAs.Size = new Size(123, 13);
			this.idLabelSaveAs.TabIndex = 5;
			this.idLabelSaveAs.Text = GenScriptWizSR.FileOptionsSaveAs;
			this.rdbMultipleFile.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.rdbMultipleFile.Location = new Point(36, 127);
			this.rdbMultipleFile.Name = "rdbMultipleFile";
			this.rdbMultipleFile.Size = new Size(365, 17);
			this.rdbMultipleFile.TabIndex = 1;
			this.rdbMultipleFile.Text = GenScriptWizSR.FileOptionScriptToClipboard;
			this.rdbMultipleFile.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.pnlMultipleFiles.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.pnlMultipleFiles.Controls.Add(this.lblDirectoryName);
			this.pnlMultipleFiles.Controls.Add(this.btnBrowseDirectories);
			this.pnlMultipleFiles.Controls.Add(this.txtDirectoryName);
			this.pnlMultipleFiles.Enabled = false;
			this.pnlMultipleFiles.Location = new Point(59, 149);
			this.pnlMultipleFiles.Name = "pnlMultipleFiles";
			this.pnlMultipleFiles.Size = new Size(389, 33);
			this.pnlMultipleFiles.TabIndex = 2;
			this.lblDirectoryName.Location = new Point(0, 4);
			this.lblDirectoryName.Name = "lblDirectoryName";
			this.lblDirectoryName.Size = new Size(123, 13);
			this.lblDirectoryName.TabIndex = 0;
			this.lblDirectoryName.Text = GenScriptWizSR.DirectoryName;
			this.btnBrowseDirectories.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnBrowseDirectories.Location = new Point(295, 2);
			this.btnBrowseDirectories.Name = "btnBrowseDirectories";
			this.btnBrowseDirectories.Size = new Size(94, 23);
			this.btnBrowseDirectories.TabIndex = 3;
			this.btnBrowseDirectories.Text = GenScriptWizSR.BrowseText;
			this.btnBrowseDirectories.Click += new EventHandler(this.btnBrowseDirectories_Click);
			this.txtDirectoryName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtDirectoryName.Location = new Point(133, 4);
			this.txtDirectoryName.Name = "txtDirectoryName";
			this.txtDirectoryName.Size = new Size(155, 20);
			this.txtDirectoryName.TabIndex = 2;
			this.txtDirectoryName.TextChanged += new EventHandler(this.OnFilePathChanged);
			this.rdbPublish.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.rdbPublish.Location = new Point(16, 132);
			this.rdbPublish.Name = "rdbPublish";
			this.rdbPublish.Size = new Size(374, 17);
			this.rdbPublish.TabIndex = 1;
			this.rdbPublish.Text = GenScriptWizSR.SelectProvider;
			this.rdbPublish.CheckedChanged += new EventHandler(this.Destination_CheckedChanged);
			this.pnlPublish.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.pnlPublish.Controls.Add(this.lblPublishWarning);
			this.pnlPublish.Controls.Add(this.cmdTargetDatabases);
			this.pnlPublish.Controls.Add(this.cmdProviders);
			this.pnlPublish.Controls.Add(this.lblTargetDatabase);
			this.pnlPublish.Controls.Add(this.lblProvider);
			this.pnlPublish.Controls.Add(this.btnProviders);
			this.pnlPublish.Enabled = false;
			this.pnlPublish.Location = new Point(25, 156);
			this.pnlPublish.Name = "pnlPublish";
			this.pnlPublish.Size = new Size(426, 94);
			this.pnlPublish.TabIndex = 2;
			this.lblPublishWarning.AutoSize = true;
			this.lblPublishWarning.Location = new Point(2, 62);
			this.lblPublishWarning.Name = "lblPublishWarning";
			this.lblPublishWarning.Size = new Size(322, 13);
			this.lblPublishWarning.TabIndex = 5;
			this.lblPublishWarning.Text = GenScriptWizSR.PublishingWarning;
			this.cmdTargetDatabases.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cmdTargetDatabases.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cmdTargetDatabases.FormattingEnabled = true;
			this.cmdTargetDatabases.Location = new Point(131, 29);
			this.cmdTargetDatabases.Name = "cmdTargetDatabases";
			this.cmdTargetDatabases.Size = new Size(195, 21);
			this.cmdTargetDatabases.TabIndex = 4;
			this.cmdTargetDatabases.SelectedIndexChanged += new EventHandler(this.cmdTargetDatabases_SelectedIndexChanged);
			this.cmdProviders.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cmdProviders.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cmdProviders.FormattingEnabled = true;
			this.cmdProviders.Location = new Point(131, 2);
			this.cmdProviders.Name = "cmdProviders";
			this.cmdProviders.Size = new Size(195, 21);
			this.cmdProviders.TabIndex = 2;
			this.cmdProviders.SelectedIndexChanged += new EventHandler(this.cmdProviders_SelectedIndexChanged);
			this.lblTargetDatabase.AutoSize = true;
			this.lblTargetDatabase.Location = new Point(2, 32);
			this.lblTargetDatabase.Name = "lblTargetDatabase";
			this.lblTargetDatabase.Size = new Size(85, 13);
			this.lblTargetDatabase.TabIndex = 0;
			this.lblTargetDatabase.Text = GenScriptWizSR.TargetDatabase;
			this.lblProvider.Location = new Point(2, 4);
			this.lblProvider.Name = "lblProvider";
			this.lblProvider.Size = new Size(127, 13);
			this.lblProvider.TabIndex = 0;
			this.lblProvider.Text = GenScriptWizSR.Provider;
			this.btnProviders.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnProviders.Location = new Point(332, 2);
			this.btnProviders.Name = "btnProviders";
			this.btnProviders.Size = new Size(94, 23);
			this.btnProviders.TabIndex = 3;
			this.btnProviders.Text = GenScriptWizSR.MoreText;
			this.btnProviders.Click += new EventHandler(this.btnProviders_Click);
			base.Controls.Add(this.pnlPublish);
			base.Controls.Add(this.panel2);
			base.Controls.Add(this.idSepScriptMode);
			base.Controls.Add(this.rdbPublish);
			base.Controls.Add(this.idRadioScriptToFile);
			base.Name = "OutputOptionsWizardPage";
			base.Size = new Size(464, 263);
			this.panel2.ResumeLayout(false);
			this.panel2.PerformLayout();
			this.pnlMultipleFiles.ResumeLayout(false);
			this.pnlMultipleFiles.PerformLayout();
			this.pnlPublish.ResumeLayout(false);
			this.pnlPublish.PerformLayout();
			base.ResumeLayout(false);
		}

		private void SaveFileType_CheckedChanged(object sender, EventArgs e)
		{
			if (this.idSaveAsANSI.Checked)
			{
				this.fileOption.SaveFileType = GenWizGeneralData.ScriptFileType.ANSI;
				return;
			}
			this.fileOption.SaveFileType = GenWizGeneralData.ScriptFileType.UNICODE;
		}

		private void Destination_CheckedChanged(object sender, EventArgs e)
		{
			this.parent.NextButton.Enabled = true;
			this.parent.FinishButton.Enabled = true;
			if (this.idRadioScriptToClipboard.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToClipboard;
			}
			else if (this.idRadioEditor.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToEditor;
			}
			else if (this.idSingleFile.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToSingleFile;
			}
			else if (this.idFilePerObject.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToFilePerObject;
			}
			if (this.idRadioScriptToFile.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToSingleFile;
			}
			else if (!this.rdbMultipleFile.Checked && this.rdbPublish.Checked)
			{
				this.fileOption.SaveScriptDestination = GenWizGeneralData.ScriptDestination.ToProvider;
				this.parent.NextButton.Enabled = false;
				this.parent.FinishButton.Enabled = false;
				this.LoadProviders();
				this.BindProviders();
			}
			this.idSaveAsANSI.Enabled = this.idRadioScriptToFile.Checked;
			this.idSaveAsUnicode.Enabled = this.idRadioScriptToFile.Checked;
			this.idSingleFile.Enabled = this.idRadioScriptToFile.Checked;
			this.idFilePerObject.Enabled = this.idRadioScriptToFile.Checked;
			this.idFileName.Enabled = this.idRadioScriptToFile.Checked;
			this.idBrowse.Enabled = this.idRadioScriptToFile.Checked;
			this.pnlPublish.Enabled = this.rdbPublish.Checked;
			this.pnlMultipleFiles.Enabled = this.rdbMultipleFile.Checked;
			this.panel2.Enabled = this.idRadioScriptToFile.Checked;
		}

		private void btnBrowseDirectories_Click(object sender, EventArgs e)
		{
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			folderBrowserDialog.Description = GenScriptWizSR.ScriptFileLocation;
			folderBrowserDialog.SelectedPath = Path.GetDirectoryName(this.fileOption.SaveFileName);
			folderBrowserDialog.RootFolder = Environment.SpecialFolder.Personal;
			DialogResult dialogResult = folderBrowserDialog.ShowDialog();
			if (DialogResult.OK == dialogResult)
			{
				this.fileOption.SaveFileName = folderBrowserDialog.SelectedPath;
				this.txtDirectoryName.Text = folderBrowserDialog.SelectedPath;
			}
		}

		private void btnProviders_Click(object sender, EventArgs e)
		{
			ProviderListDialog providerListDialog = new ProviderListDialog(this, this.parent.MessageProvider, this._providers);
			providerListDialog.ShowDialog(this);
			this.BindProviders();
			if (providerListDialog.SelectedProvider != null)
			{
				int num = 0;
				using (IEnumerator<ProviderEntity> enumerator = this._providers.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ProviderEntity current = enumerator.Current;
						if (current == providerListDialog.SelectedProvider)
						{
							this.cmdProviders.SelectedIndex = num;
							break;
						}
						num++;
					}
					return;
				}
			}
			this.cmdTargetDatabases.DataSource = null;
		}

		private void LoadProviders()
		{
			if (this._providers == null)
			{
				this.cmdTargetDatabases.DataSource = null;
				this._providers = HostingConfigurationManager.LoadProvidersFromDisk();
				if (this._providers == null)
				{
					this._providers = new ProviderCollection();
				}
				List<ProviderEntity> list = new List<ProviderEntity>();
				foreach (ProviderEntity current in this._providers)
				{
					if (!current.WasLoadedWithoutErrors)
					{
						list.Add(current);
					}
				}
				foreach (ProviderEntity current2 in list)
				{
					this._providers.Remove(current2);
				}
				this._providers.Sort(new ProvidersComparer());
			}
		}

		private void BindProviders()
		{
			this.cmdProviders.DataSource = null;
			this.cmdProviders.DataSource = this._providers;
			this.cmdProviders.DisplayMember = "Name";
		}

		private void cmdProviders_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.parent.NextButton.Enabled = true;
			this.parent.FinishButton.Enabled = true;
			if (this.cmdProviders.SelectedItem != null)
			{
				ProviderEntity providerEntity = (ProviderEntity)this.cmdProviders.SelectedItem;
				this.fileOption.Provider = providerEntity;
				providerEntity.Databases.Sort(new DatabasesComparer());
				this.cmdTargetDatabases.DataSource = null;
				this.cmdTargetDatabases.DataSource = providerEntity.Databases;
				this.cmdTargetDatabases.DisplayMember = "FullName";
				int num = -1;
				foreach (DatabaseEntity current in providerEntity.Databases)
				{
					num++;
					if (current.IsDefault)
					{
						break;
					}
				}
				this.cmdTargetDatabases.SelectedIndex = num;
				if (this.cmdTargetDatabases.SelectedItem == null)
				{
					this.parent.NextButton.Enabled = false;
					this.parent.FinishButton.Enabled = false;
					return;
				}
			}
			else
			{
				this.parent.NextButton.Enabled = false;
				this.parent.FinishButton.Enabled = false;
			}
		}

		private void cmdTargetDatabases_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.parent.NextButton.Enabled = true;
			this.parent.FinishButton.Enabled = true;
			if (this.cmdTargetDatabases.SelectedItem != null)
			{
				this.fileOption.Database = (DatabaseEntity)this.cmdTargetDatabases.SelectedItem;
				return;
			}
			this.parent.NextButton.Enabled = false;
			this.parent.FinishButton.Enabled = false;
		}
	}
}
